//
//  JXPagingTestSubListViewController.m
//  TestPrj
//
//  Created by 朱铅峰 on 2019/12/30.
//  Copyright © 2019 Xing. All rights reserved.
//

#import "JXPagingTestSubListViewController.h"

@interface JXPagingTestSubListViewController ()

proAssign NSInteger indicator;
proStrong UIColor *color;

@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);

@end

static int JXPagingTestSubListIndex = 1;

@implementation JXPagingTestSubListViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    self.indicator = JXPagingTestSubListIndex++;
    
    int r = arc4random()%255;
    int g = arc4random()%255;
    int b = arc4random()%255;
    self.color = [UIColor colorWithRed:r/255.0
                                 green:g/255.0
                                  blue:b/255.0
                                 alpha:1.0];
    
//    WEAKSELF
//    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//            [weakSelf.tableView.mj_header endRefreshing];
//        });
//    }];
//    self.tableView.mj_footer = [MJRefreshFooter footerWithRefreshingBlock:^{
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//            [weakSelf.tableView.mj_footer endRefreshing];
//        });
//    }];
}

#pragma mark - UIScrollView delegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    !self.scrollCallback ?: self.scrollCallback(scrollView);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 30;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = [NSString stringWithFormat:@"Sub%d:%d",(int)self.indicator,(int)indexPath.row];
    cell.textLabel.textColor = self.color;
    
    return cell;
}

#pragma mark - JXPagingViewListViewDelegate

- (UIView *)listView {
    return self.view;
}

- (UIScrollView *)listScrollView {
    return self.tableView;
}

- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
    self.scrollCallback = callback;
}

- (void)listDidAppear {
    NSLog(@"listDidAppear");
}

- (void)listDidDisappear {
    NSLog(@"listDidDisappear");
}

@end
